package com.example.warehouse.sys.controller;

import com.example.warehouse.common.pojo.vo.PageData;
import com.example.warehouse.common.web.JsonResult;
import com.example.warehouse.sys.pojo.vo.SysLogInFoListVO;
import com.example.warehouse.sys.service.ISysLogInFoService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 欧胤
 * @version 1.0
 * @description: TODO
 * @date 2023/7/15 2:26
 */
@Slf4j
@RestController
@RequestMapping("/sys/login_info")
@Api(tags = "7.1 登录日志")
public class SysLogInFoController {
    @Autowired
    private ISysLogInFoService service;

    @GetMapping("/list")
    @PreAuthorize("hasAuthority('/sys/login_info/list')")
    @ApiOperation("查询登录日志列表")
    @ApiOperationSupport(order = 430)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "long"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    public JsonResult list(Integer page, String queryType) {
        log.debug("开始处理【查询角色列表】的请求，页码：{}", page);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<SysLogInFoListVO> pageData;
        if ("all".equals(queryType)) {
            pageData = service.list(1, Integer.MAX_VALUE);
        } else {
            pageData = service.list(pageNum);
        }
        return JsonResult.ok(pageData);
    }

}
